<?php namespace Phpcmf\Model\Goods;

// 模块内容模型类

class Content extends \Phpcmf\Model\Content {


    // 重新获取内容
    public function _format_content_data($data) {

        // 设置sku信息
        $data['sku_value'] = dr_mall_sku_array(\Phpcmf\Service::L('input')->get('page'));

        // 查询是否优惠商品
        $data['promotion'] = [];
        $data['price_sku'] = dr_string2array($data['price_sku']);
        $data['promotion_data'] = [];
        if (APP_DIR == 'tuan' && \Phpcmf\Service::C()->tuan) {
            // 团购
            $data['promotion_data'] = \Phpcmf\Service::C()->tuan;
            if ($data['price_sku']) {
                foreach ($data['price_sku']['value'] as $i => $m) {
                    $data['promotion'][$i] = '团购价¥'.number_format(\Phpcmf\Service::C()->tuan['price_sku'][$i], 2).'元';
                }
            } else {
                $data['promotion']['price'] = '团购价¥'.number_format(\Phpcmf\Service::C()->tuan['price'], 2).'元';
            }
        } else {
            $p = \Phpcmf\Service::M('order', 'order')->get_goods_discount($data['id'], $data['price'], $this->member);
            if ($p) {
                $p['promotion'] && $data['promotion_data'] = $p['promotion'];
                if ($data['price_sku']) {
                    foreach ($data['price_sku']['value'] as $i => $m) {
                        $p = \Phpcmf\Service::M('order', 'order')->get_goods_discount($data['id'], $m['price'], $this->member);
                        $p && $data['promotion'][$i] = $p['info'];
                    }
                } else {
                    $data['promotion']['price'] = $p['info'];
                }
            }
        }



        return $data;
    }
	
	public function _call_show($data) {

        $data['thumb_sku_first'] = $data['thumb_sku_sn'] = [];
        if (is_array($data['thumb']) && is_array($data['price_sku'])) {
            // 查找firest
            $first = [];
            if (isset($data['price_sku']['name'][0]) && is_array($data['price_sku']['name'][0])) {
                foreach ($data['price_sku']['name'][0] as $t) {
                    $first[$t] = 0;
                }
            }
            // 查找sn
            $sn = [];
            if (isset($data['price_sku']['value']) && is_array($data['price_sku']['value'])) {
                foreach ($data['price_sku']['value'] as $t) {
                    if (is_array($t)) {
                        $sn[$t['sn']] = 0;
                    }
                }
            }
            foreach ($data['thumb'] as $t) {
                if (isset($sn[$t['title']])) {
                    $sn[$t['title']] = dr_get_file($t['file']);
                }
                if (isset($first[$t['title']])) {
                    $first[$t['title']] = dr_get_file($t['file']);
                }
            }
            $data['thumb_sku_sn'] = $sn;
            $data['thumb_sku_first'] = $first;
        }


        return $data;
    }

}